public class Scrambled {
 private static int a,b,x,y;
    public static void main(String[] args) throws InterruptedException {
        int i =0;
        for (;;){
            i++;
            a =0; b=0;
            x =0; y=0;
            Thread one = new Thread(new Runnable() {
                @Override
                public void run() {
                 a=1;
                 x=b;
                }
            });
            Thread two = new Thread(new Runnable() {
                @Override
                public void run() {
                    b=1;
                    y=a;
                }
            });
            one.start();two.start();
            one.join();two.join();
            String result = ("第"+i+"次"+"x="+x+"y="+y);
            if (x==0&y==0){
                System.out.println(result);
                break;
            }
        }
    }
}
